package xyz.kongbai121.demo.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xyz.kongbai121.demo.domain.ResourcesShare;
import xyz.kongbai121.demo.mapper.ResourcesShareMapper;
import xyz.kongbai121.demo.service.IResourcesShareService;

import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class ResourcesShareServiceImpl implements IResourcesShareService {

    @Autowired
    private ResourcesShareMapper shareMapper;

    @Override
    public String save(String head, String body, String from) {
        ResourcesShare share = new ResourcesShare();
        share.setHead(head);
        share.setBody(body);
        share.setAuthor(from);
        shareMapper.insert(share);
        return "成功";
    }

    @Override
    public Map<String,Object> list(String title, Page<ResourcesShare> page) {
        HashMap<String, Object> map = new HashMap<>();
        //TODO  查询资源列表
        map.put("msg",shareMapper.list(title,page));                            //数据
        map.put("total",(page.getTotal()/page.getSize())+1);                    //总页数
        map.put("current",page.getCurrent());                                   //当前页数
        return map;
    }

    @Override
    public ResourcesShare get(Long id) {
        //TODO  查询指定资源
        return shareMapper.get(id);
    }
}
